#pragma once

class MsgRoutingTarget
{
public:
	MsgRoutingTarget();

	void Redirection(sServerBody* server_body, sServerCord* server_cord) { server_body_ = server_body; server_cord_ = server_cord; }
	bool Send(CMsg* msg);
	bool IsNotExist() { return (server_body_ == NULL || server_cord_ == NULL) ? true : false; }

	unsigned long server_id() const { return server_body_->m_nID; }
	
private:
	sServerBody* server_body_;
	sServerCord* server_cord_;
};

class MsgRouter
{
public:
	MsgRouter();
	~MsgRouter();

	void Reset();

	bool Register(unsigned char content_id, sServerBody* server_body);
	bool Register(unsigned char content_id, unsigned long server_id);
	void UnRegister(unsigned char content_id);
	
	bool Send(CMsg* msg);
	
	MsgRoutingTarget* FindContentTarget(unsigned char content_id);
	MsgRoutingTarget* FindServerTarget(unsigned long server_id);

	void set_active_content(unsigned char active_content) { active_content_ = active_content; }

	static MsgRoutingTable& table() { return table_; }

private:
	unsigned char active_content_;
	std::vector<MsgRoutingTarget> contens_targets_;
	typedef std::map<unsigned long, MsgRoutingTarget*> MAP_TARGETS;
	MAP_TARGETS server_targets_;
	static MsgRoutingTable table_;
};
